package com.imy.lua.dialog;

import android.view.View;
import android.view.WindowManager;
import android.widget.EditText;
import android.widget.TextView;

import androidx.appcompat.app.AppCompatActivity;
import androidx.appcompat.widget.AppCompatCheckBox;

import com.imy.common.base.BaseDialog;
import com.imy.common.base.BaseKeyboardDialog;
import com.imy.common.util.SoftInputUtils;
import com.imy.lua.R;

public class FileNameDialog extends BaseKeyboardDialog {
    private EditText fileNameEt;
    private TextView cancelTv;
    private TextView confirmTv;
    private TextView titleTv;
    private AppCompatCheckBox checkBox;
    public FileNameDialog(AppCompatActivity activity) {
        super(activity);
    }

    public void show(String title){
        titleTv.setText(title);
        show();
    }

    public EditText getFileNameEt() {
        return fileNameEt;
    }

    public AppCompatCheckBox getCheckBox() {
        return checkBox;
    }

    @Override
    protected void init(View view) {
        super.init(view);
        titleTv=view.findViewById(R.id.title_tv);
        checkBox=view.findViewById(R.id.check_box);
        fileNameEt = view.findViewById(R.id.file_name_et);
        cancelTv = view.findViewById(R.id.cancel_tv);
        confirmTv = view.findViewById(R.id.confrim_tv);
        cancelTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
            }
        });
        confirmTv.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                dismiss();
                if (listener!=null){
                    listener.onSetFile(fileNameEt.getText().toString());
                }
            }
        });
        SoftInputUtils.showInput(fileNameEt,mActivity);
       getDialog().getWindow().clearFlags(WindowManager.LayoutParams.FLAG_ALT_FOCUSABLE_IM);
    }

    @Override
    protected int getLayoutId() {
        return R.layout.dialog_set_file_name;
    }

    public interface SetFileListener{
        void onSetFile(String fileName);
    }
    public void setFileListener(SetFileListener listener){
        this.listener=listener;
    }
    private SetFileListener listener;
}
